package cn.tedu.sp06;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
public class Sp06RibbonApplication {
	public static void main(String[] args) {
		SpringApplication.run(Sp06RibbonApplication.class, args);
	}
	@LoadBalanced //负载均衡
	@Bean //创建RestTemplate实例,并存入spring容器中
	public RestTemplate getRestTemplate() {
		//return new RestTemplate();
		//为了设置Ribbon重试重试参数,使用SimpleClientHttpRequestFactory
		SimpleClientHttpRequestFactory f = new SimpleClientHttpRequestFactory();
		f.setConnectTimeout(1000);//建立连接等待超时时间,默认是-1表示不设置
		f.setReadTimeout(1000);//连接已建立并已经发送请求,等待接收响应的超时时间,默认是-1表示不设置
		return new RestTemplate(f);
	}
}
